package com.ljx.Daoyu;

/**
 * @author 李加喜
 * @Package com.ljx.Daoyu
 * @date 2021-11-08 21:58
 */
// 岛屿最大面积
public class DaoyuMaxMianJi {
    public static void main(String[] args) {

    }
    public int maxAreaOfIsland(int[][] grid) {
        int m=grid.length,n=grid[0].length;
        int res=0;
        for (int i=0;i<m;i++){
            for (int j=0;j<n;j++){
                if (grid[i][j]==1){
                    res=Math.max(res,def(grid,i,j));
                }
            }
        }
        return res;
    }

    private int def(int[][] grid, int i, int j) {
        int m=grid.length,n=grid[0].length;
        if (i<0 || j<0 || i>=m || j>=n){
            return 0;
        }
        if (grid[i][j]==0){
            return 0;
        }
        grid[i][j]=0;
        return def(grid,i-1,j)+
        def(grid,i+1,j)+
        def(grid,i,j-1)+
        def(grid,i,j+1)+1;

    }
}
